/*************************************************************************************/
/*  HTML5-Canvas-Presentation & Editor (create presentations with a clear structure) */
/*  Copyright (C) 2012  Michael Fürst                                                */
/*                                                                                   */
/*  This program is free software; you can redistribute it and/or modify it          */
/*  under the terms of the GNU General Public License as published by the            */
/*  Free Software Foundation; either version 3 of the License, or (at your           */
/*  option) any later version.                                                       */
/*                                                                                   */
/*  This program is distributed in the hope that it will be useful, but              */
/*  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY       */
/*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License          */
/*  for more details.                                                                */
/*                                                                                   */
/*  You should have received a copy of the GNU General Public License along          */
/*  with this program; if not, see <http:/* www.gnu.org/licenses/>.                  */
/*************************************************************************************/

var Type = {normal: 0, e: 1, a: 2, ae: 3, s:4, se: 5, sa: 6, sae: 7, p:8, pe:9, pa:10, pae:11};
var Helper = new Object();

Presentation.syncPath = function(path) {
	Presentation.clearPath();
	for (var i = 0; i < path.length; i++) {
		Presentation.appendPathE(path[i].x, path[i].y, path[i].zoom, path[i].angle, path[i].time);
	}	
};

Helper.clear = function () {
	texts = [];
	path = [];
	boxes = [];
	circles = [];
	lines =  [];
	imgs =  [];
	vids =  [];
	audios =  [];
};

Helper.removeObj = function (obj) {
	if (obj == null) return;
	var pointer = obj.pos;
	var file = document.getElementById("code").value;
	var start = true;
	var inc = 0;
	while (inc > 0 || start == true) {
		pointer++;
		if (file[pointer] == "(") {
			inc++;
			if (start == true) {
				start = false;
			}
		} else if (file[pointer] == ")") {
			inc--;
		}
	}
	pointer++;
	file = file.substring(0, obj.pos+1)+file.substring(pointer+1, file.length);
	document.getElementById("code").value = file;
	JSHelper.fromFile();
};


/* modifying an object and update the script */
Helper.updateObj = function(obj, str) {
	var pointer = obj.pos;
	var file = document.getElementById("code").value;
	var start = true;
	var inc = 0;
	while (inc > 0 || start == true) {
		pointer++;
		if (file[pointer] == "(") {
			inc++;
			if (start == true) {
				start = false;
			}
		} else if (file[pointer] == ")") {
			inc--;
		}
	}
	pointer++;
	file = file.substring(0, obj.pos+1)+"\t"+str+file.substring(pointer, file.length);
	document.getElementById("code").value = file;
	JSLinker.fromFile();
};

Helper.updateBackground = function(style) {
	var regex = "StyleLib.themes."+StyleLib.stringifyTheme(theme.background);
	var file = document.getElementById("code").value;
	file = file.replace(regex, "StyleLib.themes."+style);
	document.getElementById("code").value = file;
	JSLinker.fromFile();
};

Helper.updateUnknown = function (obj) {
	if (!(obj.str === undefined)) {
		Helper.updateText(obj);
	} else if (!(obj.x3 === undefined)) {
		Helper.updateLine(obj);
	} else if (!(obj.radius === undefined)) {
		Helper.updateCircle(obj);
	} else if (!(obj.video === undefined)) {
		Helper.updateVid(obj);
	} else if (!(obj.time === undefined)) {
		Helper.updatePath(obj);
	} else if (!(obj.width === undefined) && !(obj.scalar === undefined)) {
		Helper.updateImg(obj);
	} else {
		Helper.updateBox(obj);
	}
};

Helper.updateText = function(obj) {
	Helper.updateObj(obj, Helper.text_stringify(obj));
};
Helper.updateBox = function(obj) {
	Helper.updateObj(obj, Helper.box_stringify(obj));
};
Helper.updateLine = function(obj) {
	Helper.updateObj(obj, Helper.line_stringify(obj));
};
Helper.updateCircle = function(obj) {
	Helper.updateObj(obj, Helper.circle_stringify(obj));
};
Helper.updateImg = function(obj) {
	Helper.updateObj(obj, Helper.img_stringify(obj));
};
Helper.updateVid = function(obj) {
	Helper.updateObj(obj, Helper.vid_stringify(obj));
};
Helper.updatePath = function(obj) {
	Helper.updateObj(obj, Helper.path_stringify(obj));
};

Helper.newText = function(x, y, str, size, angle) {
	JSLinker.render = JSLinker.render + "\tPresentation.text("+x+","+y+",'"+str+"',"+size+","+angle+");\n";
	JSLinker.toFile();
	JSLinker.fromFile();
};
Helper.newCircle = function(x, y, radius) {
	JSLinker.render = JSLinker.render + "\tPresentation.circle("+x+","+y+","+radius+",false);\n";
	JSLinker.toFile();
	JSLinker.fromFile();
};
Helper.newLine = function(x, y, x2, y2) {
	JSLinker.render = JSLinker.render + "\tPresentation.line("+x+","+y+","+x2+","+y2+");\n";
	JSLinker.toFile();
	JSLinker.fromFile();
};
Helper.newBox = function(x, y, width, height, angle) {
	JSLinker.render = JSLinker.render + "\tPresentation.box("+x+","+y+","+width+","+height+",false,"+angle+",false);\n";
	JSLinker.toFile();
	JSLinker.fromFile();
};
Helper.newImg = function(src, x, y, scalar, angle) {
};
Helper.newVid = function(src, x, y, scalar, angle, begin, end) {
};


/* Linking objects with scripts and vice versa */

/* TEXT */
Helper.pushText = function(npos, nx, ny, nstr, nsize, nangle) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nstr = nstr.substring(1, nstr.length-1);
	nsize = parseFloat(eval(nsize));
	nangle = parseFloat(eval(nangle));
	texts[texts.length] = {x:nx, y:ny, x2:nx, y2:ny, str:nstr, size:nsize, size2:nsize, angle:nangle, angle2:nangle, begin:0, end:100000, type:Type.normal, pos:npos};
};
Helper.pushTextA = function(npos, nx, ny, nx2, ny2, nstr, nsize, nsize2, nangle, nangle2, nbegin, nend) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nstr = nstr.substring(1, nstr.length-1);
	nsize = parseFloat(eval(nsize));
	nangle = parseFloat(eval(nangle));
	nsize2 = parseFloat(eval(nsize2));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	texts[texts.length] = {x:nx, y:ny, x2:nx2, y2:ny2, str:nstr, size:nsize, size2:nsize2, angle:nangle, angle2:nangle2, begin:nbegin, end:nbegin, type:Type.a, pos:npos};
};
Helper.pushTextAE = function(npos, nx, ny, nx2, ny2, nstr, nsize, nsize2, nangle, nangle2, nbegin, nend) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nstr = nstr.substring(1, nstr.length-1);
	nsize = parseFloat(eval(nsize));
	nangle = parseFloat(eval(nangle));
	nsize2 = parseFloat(eval(nsize2));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	texts[texts.length] = {x:nx, y:ny, x2:nx2, y2:ny2, str:nstr, size:nsize, size2:nsize2, angle:nangle, angle2:nangle2, begin:nbegin, end:nbegin, type:Type.ae, pos:npos};
};
Helper.pushTextE = function(npos, nx, ny, nstr, nsize, nangle, nbegin, nend) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nstr = nstr.substring(1, nstr.length-1);
	nsize = parseFloat(eval(nsize));
	nangle = parseFloat(eval(nangle));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	texts[texts.length] = {x:nx, y:ny, x2:nx, y2:ny, str:nstr, size:nsize, size2:nsize, angle:nangle, angle2:nangle, begin:nbegin, end:nend, type:Type.e, pos:npos};
};
Helper.text_stringify = function(text) {
	if (text.type == Type.normal) {
		return "Presentation.text("+text.x+","+text.y+",'"+text.str+"',"+text.size+","+text.angle+")";
	} else if (text.type == Type.a) {
		return "Presentation.textA("+text.x+","+text.y+","+text.x2+","+text.y2+",'"+text.str+"',"+text.size+","+text.size2+","+text.angle+","+text.angle2+","+text.begin+","+text.end+")";
	} else if (text.type == Type.ae) {
		return "Presentation.textAE("+text.x+","+text.y+","+text.x2+","+text.y2+",'"+text.str+"',"+text.size+","+text.size2+","+text.angle+","+text.angle2+","+text.begin+","+text.end+")";
	} else if (text.type == Type.e) {
		return "Presentation.textE("+text.x+","+text.y+",'"+text.str+"',"+text.size+","+text.angle+","+text.begin+","+text.end+")";
	}
};

/* BOX */
Helper.pushBox = function(npos, nx, ny, nwidth, nheight, nround,nangle,nfilled) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nround = eval(nround == "true");
	nangle = parseFloat(eval(nangle));
	nfilled = eval(nfilled == "true");
	boxes[boxes.length] = {x:nx, y:ny, x2:nx, y2:ny, width:nwidth, width2:nwidth, height:nheight, height2:nheight, angle:nangle, angle2:nangle, b_round:nround, begin:0, end:100000, type:Type.normal, pos:npos, filled:nfilled};
};
Helper.pushBoxE = function(npos, nx, ny, nwidth, nheight, nround,nangle,nbegin,nend,nfilled) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nround = eval(nround) == "true";
	nangle = parseFloat(eval(nangle));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	nfilled = eval(nfilled == "true");
	boxes[boxes.length] = {x:nx, y:ny, x2:nx, y2:ny, width:nwidth, width2:nwidth, height:nheight, height2:nheight, angle:nangle, angle2:nangle, b_round:nround, begin:nbegin, end:nend, type:Type.e, pos:npos, filled:nfilled};
};
Helper.pushBoxA = function(npos, nx, ny, nx2, ny2, nwidth, nheight, nwidth2, nheight2, nround,nangle,nangle2,nbegin,nend,nfilled) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nwidth2 = parseFloat(eval(nwidth2));
	nheight2 = parseFloat(eval(nheight2));
	nround = eval(nround) == "true";
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	nfilled = eval(nfilled == "true");
	boxes[boxes.length] = {x:nx, y:ny, x2:nx2, y2:ny2, width:nwidth, width2:nwidth2, height:nheight, height2:nheight2, angle:nangle, angle2:nangle2, b_round:nround, begin:nbegin, end:nend, type:Type.a, pos:npos, filled:nfilled};
};
Helper.pushBoxAE = function(npos, nx, ny, nx2, ny2, nwidth, nheight, nwidth2, nheight2, nround,nangle,nangle2,nbegin,nend,nfilled) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nwidth2 = parseFloat(eval(nwidth2));
	nheight2 = parseFloat(eval(nheight2));
	nround = eval(nround) == "true";
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	nfilled = eval(nfilled == "true");
	boxes[boxes.length] = {x:nx, y:ny, x2:nx2, y2:ny2, width:nwidth, width2:nwidth2, height:nheight, height2:nheight2, angle:nangle, angle2:nangle2, b_round:nround, begin:nbegin, end:nend, type:Type.ae, pos:npos, filled:nfilled};
};
Helper.box_stringify = function(box) {
	if (box.type == Type.normal) {
		return "Presentation.box("+box.x+","+box.y+","+box.width+","+box.height+","+box.angle+","+box.filled+")";
	} else if (box.type == Type.a) {
		return "Presentation.boxA("+box.x+","+box.y+","+box.x2+","+box.y2+","+box.width+","+box.height+","+box.width2+","+box.height2+","+box.angle+","+box.angle2+","+box.begin+","+box.end+","+box.filled+")";
	} else if (box.type == Type.ae) {
		return "Presentation.boxAE("+box.x+","+box.y+","+box.x2+","+box.y2+","+box.width+","+box.height+","+box.width2+","+box.height2+","+box.angle+","+box.angle2+","+box.begin+","+box.end+","+box.filled+")";
	} else if (box.type == Type.e) {
		return "Presentation.boxE("+box.x+","+box.y+","+box.width+","+box.height+","+box.angle+","+box.begin+","+box.end+","+box.filled+")";
	}
};

/* CIRCLE */
Helper.pushCircle = function(npos, nx, ny, nradius, nfilled) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nradius = parseFloat(eval(nradius));
	nfilled = eval(nfilled == "true");
	circles[circles.length] = {x:nx, y:ny, x2:nx, y2:ny, radius:nradius, radius2:nradius, begin:0, end:100000, type:Type.normal, pos:npos, filled:nfilled};
};
Helper.pushCircleE = function(npos, nx, ny, nradius,nbegin,nend,nfilled) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nradius = parseFloat(eval(nradius));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	nfilled = eval(nfilled == "true");
	circles[circles.length] = {x:nx, y:ny, x2:nx, y2:ny, radius:nradius, radius2:nradius, begin:nbegin, end:nend, type:Type.e, pos:npos, filled:nfilled};
};
Helper.pushCircleA = function(npos, nx, ny, nx2, ny2, nradius,nradius2,nbegin,nend,nfilled) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nradius = parseFloat(eval(nradius));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nradius2 = parseFloat(eval(nradius2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	nfilled = eval(nfilled == "true");
	circles[circles.length] = {x:nx, y:ny, x2:nx2, y2:ny2, radius:nradius, radius2:nradius2, begin:nbegin, end:nend, type:Type.a, pos:npos, nfilled:nfilled};
};
Helper.pushCircleAE = function(npos, nx, ny, nx2, ny2, nradius,nradius2,nbegin,nend) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nradius = parseFloat(eval(nradius));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nradius2 = parseFloat(eval(nradius2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	nfilled = eval(nfilled == "true");
	circles[circles.length] = {x:nx, y:ny, x2:nx2, y2:ny2, radius:nradius, radius2:nradius2, begin:nbegin, end:nend, type:Type.ae, pos:npos, nfilled:nfilled};
};
Helper.circle_stringify = function(circle) {
	if (circle.type == Type.normal) {
		return "Presentation.circle("+circle.x+","+circle.y+","+circle.radius+","+circle.filled+")";
	} else if (circle.type == Type.a) {
		return "Presentation.circleA("+circle.x+","+circle.y+","+circle.x2+","+circle.y2+","+circle.radius+","+circle.radius2+","+box.begin+","+box.end+","+circle.filled+")";
	} else if (circle.type == Type.ae) {
		return "Presentation.circleAE("+circle.x+","+circle.y+","+circle.x2+","+circle.y2+","+circle.radius+","+circle.radius2+","+box.begin+","+box.end+","+circle.filled+")";
	} else if (circle.type == Type.e) {
		return "Presentation.circleE("+circle.x+","+circle.y+","+circle.radius+","+box.begin+","+box.end+","+circle.filled+")";
	}
};

/* LINE */
Helper.pushLine = function(npos, nx, ny, nx2, ny2) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	lines[lines.length] = {x:nx, y:ny, x2:nx2, y2:ny2, x3:nx, y3:ny, x4:nx2, y4:ny2, begin:0, end:100000, type:Type.normal, pos:npos};
};
Helper.pushLineE = function(npos, nx, ny, nx2, ny2, nbegin, nend) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	lines[lines.length] = {x:nx, y:ny, x2:nx2, y2:ny2, x3:nx, y3:ny, x4:nx2, y4:ny2, begin:nbegin, end:nend, type:Type.e, pos:npos};
};
Helper.pushLineA = function(npos, nx, ny, nx2, ny2, nx3, ny3, nx4, ny4, nbegin, nend) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nx3 = parseFloat(eval(nx3));
	ny3 = parseFloat(eval(ny3));
	nx4 = parseFloat(eval(nx4));
	ny4 = parseFloat(eval(ny4));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	lines[lines.length] = {x:nx, y:ny, x2:nx2, y2:ny2, x3:nx3, y3:ny3, x4:nx4, y4:ny4, begin:nbegin, end:nend, type:Type.a, pos:npos};
};
Helper.pushLineAE = function(npos, nx, ny, nx2, ny2, nx3, ny3, nx4, ny4, nbegin, nend) {
	nx = parseFloat(eval(nx));
	ny = parseFloat(eval(ny));
	nx2 = parseFloat(eval(nx2));
	ny2 = parseFloat(eval(ny2));
	nx3 = parseFloat(eval(nx3));
	ny3 = parseFloat(eval(ny3));
	nx4 = parseFloat(eval(nx4));
	ny4 = parseFloat(eval(ny4));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	lines[lines.length] = {x:nx, y:ny, x2:nx2, y2:ny2, x3:nx3, y3:ny3, x4:nx4, y4:ny4, begin:nbegin, end:nend, type:Type.ae, pos:npos};
};
Helper.line_stringify = function(line) {
	if (line.type == Type.normal) {
		return "Presentation.line("+line.x+","+line.y+","+line.x2+","+line.y2+")";
	} else if (line.type == Type.a) {
		return "Presentation.lineA("+line.x+","+line.y+","+line.x2+","+line.y2+","+line.x3+","+line.y3+","+line.x4+","+line.y4+","+line.begin+","+line.end+")";
	} else if (line.type == Type.ae) {
		return "Presentation.lineAE("+line.x+","+line.y+","+line.x2+","+line.y2+","+line.x3+","+line.y3+","+line.x4+","+line.y4+","+line.begin+","+line.end+")";
	} else if (line.type == Type.e) {
		return "Presentation.lineE("+line.x+","+line.y+","+line.x2+","+line.y2+","+line.begin+","+line.end+")";
	}
};

/* IMAGE */
Helper.pushImg = function(npos, nid, nx, ny, nangle) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nangle = parseFloat(eval(nangle));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2: 0, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle, begin:0, end:100000, type:Type.normal, pos:npos};
};
Helper.pushImgE = function(npos, nid, nx, ny, nangle, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nangle = parseFloat(eval(nangle));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2: 0, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle, begin:nbegin, end:nend, type:Type.e, pos:npos};
};
Helper.pushImgS = function(npos, nid, nx, ny, nwidth, nheight, nangle) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nangle = parseFloat(eval(nangle));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2: 0, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle, begin:0, end:100000, type:Type.s, pos:npos};
};
Helper.pushImgSE = function(npos, nid, nx, ny, nwidth, nheight, nangle, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nangle = parseFloat(eval(nangle));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:nwidth, height:nheight, width2:nwidth, height2:nheight, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle, begin:nbegin, end:nend, type:Type.se, pos:npos};
};
Helper.pushImgSA = function(npos, nid, nx, ny, nx2, ny2, nwidth, nheight, nwidth2, nheight2, nangle, nangle2, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	ny2 = parseFloat(eval(ny2));
	nx2 = parseFloat(eval(nx2));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nwidth2 = parseFloat(eval(nwidth2));
	nheight2 = parseFloat(eval(nheight2));
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx2, y2:ny2, width:nwidth, height:nheight, width2:nwidth2, height2:nheight2, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle2, begin:nbegin, end:nend, type:Type.sa, pos:npos};
};
Helper.pushImgSAE = function(npos, nid, nx, ny, nx2, ny2, nwidth, nheight, nwidth2, nheight2, nangle, nangle2, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	ny2 = parseFloat(eval(ny2));
	nx2 = parseFloat(eval(nx2));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nwidth2 = parseFloat(eval(nwidth2));
	nheight2 = parseFloat(eval(nheight2));
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx2, y2:ny2, width:nwidth, height:nheight, width2:nwidth2, height2:nheight2, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle2, begin:nbegin, end:nend, type:Type.sae, pos:npos};
};
Helper.pushImgP = function(npos, nid, nx, ny, nscalar, nangle) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nscalar = parseFloat(eval(nscalar));
	nangle = parseFloat(eval(nangle));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2:0, scalar:nscalar, scalar2:nscalar ,angle:nangle, angle2:nangle, begin:0, end:100000, type:Type.p, pos:npos};
};
Helper.pushImgPE = function(npos, nid, nx, ny, nscalar, nangle, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nscalar = parseFloat(eval(nscalar));
	nangle = parseFloat(eval(nangle));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2:0, scalar:nscalar, scalar2:nscalar ,angle:nangle, angle2:nangle, begin:nbegin, end:nend, type:Type.pe, pos:npos};
};
Helper.pushImgPA = function(npos, nid, nx, ny, nx2, ny2, nscalar, nscalar2, nangle, nangle2, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	ny2 = parseFloat(eval(ny2));
	nx2 = parseFloat(eval(nx2));
	nscalar = parseFloat(eval(nscalar));
	nscalar2 = parseFloat(eval(nscalar2));
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx2, y2:ny2, width:0, height:0, width2:0, height2:0, scalar:nscalar, scalar2:nscalar2 ,angle:nangle, angle2:nangle2, begin:nbegin, end:nend, type:Type.pa, pos:npos};
};
Helper.pushImgPAE = function(npos, nid, nx, ny, nx2, ny2, nscalar, nscalar2, nangle, nangle2, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	ny2 = parseFloat(eval(ny2));
	nx2 = parseFloat(eval(nx2));
	nscalar = parseFloat(eval(nscalar));
	nscalar2 = parseFloat(eval(nscalar2));
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	imgs[imgs.length] = {id: nid, x:nx, y:ny, x2:nx2, y2:ny2, width:0, height:0, width2:0, height2:0, scalar:nscalar, scalar2:nscalar2 ,angle:nangle, angle2:nangle2, begin:nbegin, end:nend, type:Type.pae, pos:npos};
};
Helper.img_stringify = function(img) {
	if (img.type == Type.normal) {
		return "Presentation.img("+img.id+","+img.x+","+img.y+","+img.angle+")";
	} else if (img.type == Type.e) {
		return "Presentation.imgE("+img.id+","+img.x+","+img.y+","+img.angle+","+img.begin+","+img.end+")";
	} else if (img.type == Type.s) {
		return "Presentation.imgS("+img.id+","+img.x+","+img.y+","+img.width+","+img.height+","+img.angle+")";
	} else if (img.type == Type.se) {
		return "Presentation.imgSE("+img.id+","+img.x+","+img.y+","+img.width+","+img.height+","+img.angle+","+img.begin+","+img.end+")";
	} else if (img.type == Type.sa) {
		return "Presentation.imgSA("+img.id+","+img.x+","+img.y+","+img.x2+","+img.y2+","+img.width+","+img.height+","+img.width2+","+img.height2+","+img.angle+","+img.angle2+","+img.begin+","+img.end+")";
	} else if (img.type == Type.sae) {
		return "Presentation.imgSAE("+img.id+","+img.x+","+img.y+","+img.x2+","+img.y2+","+img.width+","+img.height+","+img.width2+","+img.height2+","+img.angle+","+img.angle2+","+img.begin+","+img.end+")";
	} else if (img.type == Type.p) {
		return "Presentation.imgP("+img.id+","+img.x+","+img.y+","+img.scalar+","+img.angle+")";
	} else if (img.type == Type.pe) {
		return "Presentation.imgPE("+img.id+","+img.x+","+img.y+","+img.scalar+","+img.angle+","+img.begin+","+img.end+")";
	} else if (img.type == Type.pa) {
		return "Presentation.imgPA("+img.id+","+img.x+","+img.y+","+img.x2+","+img.y2+","+img.scalar+","+img.scalar2+","+img.angle+","+img.angle2+","+img.begin+","+img.end+")";
	} else if (img.type == Type.pae) {
		return "Presentation.imgPAE("+img.id+","+img.x+","+img.y+","+img.x2+","+img.y2+","+img.scalar+","+img.scalar2+","+img.angle+","+img.angle2+","+img.begin+","+img.end+")";
	}
};

/* VIDEO */
Helper.pushVid = function(npos, nid, nx, ny, nangle) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nangle = parseFloat(eval(nangle));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2: 0, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle, begin:0, end:100000, type:Type.normal, pos:npos, video:true};
};
Helper.pushVidE = function(npos, nid, nx, ny, nangle, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nangle = parseFloat(eval(nangle));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2: 0, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle, begin:nbegin, end:nend, type:Type.e, pos:npos, video:true};
};
Helper.pushVidS = function(npos, nid, nx, ny, nwidth, nheight, nangle) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nangle = parseFloat(eval(nangle));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2: 0, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle, begin:0, end:100000, type:Type.s, pos:npos, video:true};
};
Helper.pushVidSE = function(npos, nid, nx, ny, nwidth, nheight, nangle, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nangle = parseFloat(eval(nangle));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:nwidth, height:nheight, width2:nwidth, height2:nheight, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle, begin:nbegin, end:nend, type:Type.se, pos:npos, video:true};
};
Helper.pushVidSA = function(npos, nid, nx, ny, nx2, ny2, nwidth, nheight, nwidth2, nheight2, nangle, nangle2, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	ny2 = parseFloat(eval(ny2));
	nx2 = parseFloat(eval(nx2));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nwidth2 = parseFloat(eval(nwidth2));
	nheight2 = parseFloat(eval(nheight2));
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx2, y2:ny2, width:nwidth, height:nheight, width2:nwidth2, height2:nheight2, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle2, begin:nbegin, end:nend, type:Type.sa, pos:npos, video:true};
};
Helper.pushVidSAE = function(npos, nid, nx, ny, nx2, ny2, nwidth, nheight, nwidth2, nheight2, nangle, nangle2, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	ny2 = parseFloat(eval(ny2));
	nx2 = parseFloat(eval(nx2));
	nwidth = parseFloat(eval(nwidth));
	nheight = parseFloat(eval(nheight));
	nwidth2 = parseFloat(eval(nwidth2));
	nheight2 = parseFloat(eval(nheight2));
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx2, y2:ny2, width:nwidth, height:nheight, width2:nwidth2, height2:nheight2, scalar:1, scalar2: 1 ,angle:nangle, angle2:nangle2, begin:nbegin, end:nend, type:Type.sae, pos:npos, video:true};
};
Helper.pushVidP = function(npos, nid, nx, ny, nscalar, nangle) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nscalar = parseFloat(eval(nscalar));
	nangle = parseFloat(eval(nangle));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2:0, scalar:nscalar, scalar2:nscalar ,angle:nangle, angle2:nangle, begin:0, end:100000, type:Type.p, pos:npos, video:true};
};
Helper.pushVidPE = function(npos, nid, nx, ny, nscalar, nangle, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nscalar = parseFloat(eval(nscalar));
	nangle = parseFloat(eval(nangle));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx, y2:ny, width:0, height:0, width2:0, height2:0, scalar:nscalar, scalar2:nscalar ,angle:nangle, angle2:nangle, begin:nbegin, end:nend, type:Type.pe, pos:npos, video:true};
};
Helper.pushVidPA = function(npos, nid, nx, ny, nx2, ny2, nscalar, nscalar2, nangle, nangle2, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	ny2 = parseFloat(eval(ny2));
	nx2 = parseFloat(eval(nx2));
	nscalar = parseFloat(eval(nscalar));
	nscalar2 = parseFloat(eval(nscalar2));
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx2, y2:ny2, width:0, height:0, width2:0, height2:0, scalar:nscalar, scalar2:nscalar2 ,angle:nangle, angle2:nangle2, begin:nbegin, end:nend, type:Type.pa, pos:npos, video:true};
};
Helper.pushVidPAE = function(npos, nid, nx, ny, nx2, ny2, nscalar, nscalar2, nangle, nangle2, nbegin, nend) {
	nid = parseFloat(eval(nid));
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	ny2 = parseFloat(eval(ny2));
	nx2 = parseFloat(eval(nx2));
	nscalar = parseFloat(eval(nscalar));
	nscalar2 = parseFloat(eval(nscalar2));
	nangle = parseFloat(eval(nangle));
	nangle2 = parseFloat(eval(nangle2));
	nbegin = parseFloat(eval(nbegin));
	nend = parseFloat(eval(nend));
	vids[vids.length] = {id: nid, x:nx, y:ny, x2:nx2, y2:ny2, width:0, height:0, width2:0, height2:0, scalar:nscalar, scalar2:nscalar2 ,angle:nangle, angle2:nangle2, begin:nbegin, end:nend, type:Type.pae, pos:npos, video:true};
};
Helper.vid_stringify = function(vid) {
	if (vid.type == Type.normal) {
		return "Presentation.vid("+vid.id+","+vid.x+","+vid.y+","+vid.angle+")";
	} else if (vid.type == Type.e) {
		return "Presentation.vidE("+vid.id+","+vid.x+","+vid.y+","+vid.angle+","+vid.begin+","+vid.end+")";
	} else if (vid.type == Type.s) {
		return "Presentation.vidS("+vid.id+","+vid.x+","+vid.y+","+vid.width+","+vid.height+","+vid.angle+")";
	} else if (vid.type == Type.se) {
		return "Presentation.vidSE("+vid.id+","+vid.x+","+vid.y+","+vid.width+","+vid.height+","+vid.angle+","+vid.begin+","+vid.end+")";
	} else if (vid.type == Type.sa) {
		return "Presentation.vidSA("+vid.id+","+vid.x+","+vid.y+","+vid.x2+","+vid.y2+","+vid.width+","+vid.height+","+vid.width2+","+vid.height2+","+vid.angle+","+vid.angle2+","+vid.begin+","+vid.end+")";
	} else if (vid.type == Type.sae) {
		return "Presentation.vidSAE("+vid.id+","+vid.x+","+vid.y+","+vid.x2+","+vid.y2+","+vid.width+","+vid.height+","+vid.width2+","+vid.height2+","+vid.angle+","+vid.angle2+","+vid.begin+","+vid.end+")";
	} else if (vid.type == Type.p) {
		return "Presentation.vidP("+vid.id+","+vid.x+","+vid.y+","+vid.scalar+","+vid.angle+")";
	} else if (vid.type == Type.pe) {
		return "Presentation.vidPE("+vid.id+","+vid.x+","+vid.y+","+vid.scalar+","+vid.angle+","+vid.begin+","+vid.end+")";
	} else if (img.type == Type.pa) {
		return "Presentation.vidPA("+vid.id+","+vid.x+","+vid.y+","+vid.x2+","+vid.y2+","+vid.scalar+","+vid.scalar2+","+vid.angle+","+vid.angle2+","+vid.begin+","+vid.end+")";
	} else if (vid.type == Type.pae) {
		return "Presentation.vidPAE("+vid.id+","+vid.x+","+vid.y+","+vid.x2+","+vid.y2+","+vid.scalar+","+vid.scalar2+","+vid.angle+","+vid.angle2+","+vid.begin+","+vid.end+")";
	}
};

/* PATH */
Helper.pushPath = function(npos, nx, ny, nzoom, nangle) {
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nzoom = parseFloat(eval(nzoom));
	nangle = parseFloat(eval(nangle));
	path[path.length] = {x:nx, y:ny, scalar:nzoom, angle:nangle, time:500, type:Type.normal, pos:npos};
};
Helper.pushPathE = function(npos, nx, ny, nzoom, nangle, ntime) {
	ny = parseFloat(eval(ny));
	nx = parseFloat(eval(nx));
	nzoom = parseFloat(eval(nzoom));
	nangle = parseFloat(eval(nangle));
	ntime = parseFloat(eval(ntime));
	path[path.length] = {x:nx, y:ny, scalar:nzoom, angle:nangle, time:ntime, type:Type.e, pos:npos};
};
Helper.path_stringify = function(pathpoint) {
	if (pathpoint.type == Type.normal) {
		return "Presentation.appendPath("+pathpoint.x+","+pathpoint.y+","+pathpoint.scalar+","+pathpoint.angle+")";
	} else if (pathpoint.type == Type.e) {
		return "Presentation.appendPathE("+pathpoint.x+","+pathpoint.y+","+pathpoint.scalar+","+pathpoint.angle+","+pathpoint.begin+","+pathpoint.end+")";
	}
}
